String clazzTpl({package}) => """
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:$package/route/main.route.dart';

enum ThemeType {
  dark,
  light,
  system,
}

extension ThemeStateEx on ThemeState {
  Brightness get brightness {
    switch (type) {
      case ThemeType.light:
        return Brightness.light;
      case ThemeType.dark:
        return Brightness.dark;
      case ThemeType.system:
        if (globalNavigatorKey.currentContext != null) {
          return MediaQuery.platformBrightnessOf(
              globalNavigatorKey.currentContext!);
        } else {
          return Brightness.light;
        }
    }
  }

  set brightness(Brightness brightness) {
    switch (brightness) {
      case Brightness.light:
        type = ThemeType.light;
        break;
      case Brightness.dark:
        type = ThemeType.dark;
        break;
    }
  }

  ThemeMode get themeMode {
    switch (type) {
      case ThemeType.light:
        return ThemeMode.light;
      case ThemeType.dark:
        return ThemeMode.dark;
      case ThemeType.system:
        return ThemeMode.system;
    }
  }

  SystemUiOverlayStyle get light => SystemUiOverlayStyle.light;

  SystemUiOverlayStyle get dark => SystemUiOverlayStyle.dark;

  SystemUiOverlayStyle get systemOverlayStyle {
    switch (type) {
      case ThemeType.light:
        return SystemUiOverlayStyle.light;
      case ThemeType.dark:
        return SystemUiOverlayStyle.dark;
      case ThemeType.system:
        if (globalNavigatorKey.currentContext != null) {
          var brightness = MediaQuery.platformBrightnessOf(
              globalNavigatorKey.currentContext!);
          if (brightness == Brightness.light) {
            return SystemUiOverlayStyle.light;
          } else {
            return SystemUiOverlayStyle.dark;
          }
        } else {
          return SystemUiOverlayStyle.light;
        }
    }
  }

  SystemUiOverlayStyle get systemOverlayStyleReverse {
    switch (type) {
      case ThemeType.light:
        return SystemUiOverlayStyle.dark;
      case ThemeType.dark:
        return SystemUiOverlayStyle.light;
      case ThemeType.system:
        if (globalNavigatorKey.currentContext != null) {
          var brightness = MediaQuery.platformBrightnessOf(
              globalNavigatorKey.currentContext!);
          if (brightness == Brightness.light) {
            return SystemUiOverlayStyle.dark;
          } else {
            return SystemUiOverlayStyle.light;
          }
        } else {
          return SystemUiOverlayStyle.dark;
        }
    }
  }
}

abstract class ThemeStateInterface {
  Color theme({required Color dark, required Color light});
}

class ThemeState extends ThemeStateInterface {
  ThemeType type;

  ThemeState(this.type);

  static ThemeState initialState() {
    return ThemeState(ThemeType.light);
  }

  static ThemeState fromJson(dynamic json) {
    return ThemeState(
      json["type"] != null ? formatThemeType(json["type"]) : ThemeType.light,
    );
  }

  dynamic toJson() => {
        'type': type.name,
      };

  ThemeState copyWith({
    type,
  }) {
    return ThemeState(type ?? this.type);
  }

  static ThemeType formatThemeType(String key) {
    switch (key) {
      case 'dark':
        return ThemeType.dark;
      case 'light':
        return ThemeType.light;
      case 'system':
        return ThemeType.system;
      default:
        return ThemeType.light;
    }
  }

  @override
  Color theme({required Color dark, required Color light}) {
    if (type == ThemeType.system) {
      if (globalNavigatorKey.currentContext != null) {
        var brightness =
            MediaQuery.platformBrightnessOf(globalNavigatorKey.currentContext!);
        type =
            brightness == Brightness.light ? ThemeType.light : ThemeType.dark;
      } else {
        type = ThemeType.light;
      }
    }
    return {ThemeType.dark: dark, ThemeType.light: light}[type]!;
  }

  /// 模块化，不要在这里写 get 方法, 在ThemeStateInterface 使用with
  Color get title => theme(dark: Colors.white, light: const Color(0xff3c3f41));

  Color get body => theme(dark: const Color(0xff3c3f41), light: Colors.white);
}
""";
